#include "geometry.h"
#include "DCELMesh.h"
#include "DCELFace.h"
#include "DCELVertex.h"

typedef std::vector<DCELHalfEdge*> GPDHFLIST;

#pragma once

#ifndef POINTLOCATIONDAG_H_
#define POINTLOCATIONDAG_H_

struct PLDAGEdge{
	DCELVertex start;
	DCELVertex end;
	PLDAGEdge();
};


class PointLocationDAG
{
public:
	//variables
	DCELFace *face;
	PointLocationDAG *pd[3];
	PLDAGEdge edge[3];

	//function
	PointLocationDAG();
	~PointLocationDAG();
	void setNode(DCELFace* df);
	bool clear();
};

#define REAL double
typedef struct VERTEX2D_TYP {
	REAL x;
	REAL y;
} VERTEX2D, *VERTEX2D_PTR;

class DelaunayTriangulation :
	public Graph
{
public:
	DelaunayTriangulation(void);
	~DelaunayTriangulation(void);

	int generateTriangulation(double time);
	void AddBoundingTriangle();
	void RemoveBoundingTriangle();
	bool findBelongTriangle(Site site, PointLocationDAG* location, DCELFace** pBelongFace, DCELHalfEdge** pBelongEdge);
	int isBelong(Site site, PointLocationDAG* location, DCELHalfEdge **onEge);
	double CounterClockWise(DCELVertex* origin, DCELVertex* end, Site site);
	void legalizeEge(DCELVertex* pr, DCELHalfEdge* dhf);
	bool isLegal(DCELVertex* pr, DCELHalfEdge* dhf);
	double InOutCircle(VERTEX2D_PTR pa, VERTEX2D_PTR pb, VERTEX2D_PTR pc, VERTEX2D_PTR pp);
	bool onTheSegment(VERTEX2D start,VERTEX2D end, VERTEX2D test);
	double distance(VERTEX2D n1, VERTEX2D n2);
	bool BFS(double breach_weight, DCELVertex* start, DCELVertex* end, GPDHFLIST &pVecEdge);
	void ResetVertexStatus();
	void ResetHalfEdgeColor();

public:
	DCELMesh mesh_;
	PointLocationDAG location;
	DCELVertex *p_1; //store the p-1 information
	DCELVertex *p_2; // store the p-2 information
	DCELVertex *pDVUpRight;
	VERTEX2D m_verUpRight;
};

#endif